package base.src;

import android.bluetooth.BluetoothSocket;
import base.game.Player;
import base.game.Shot;

import communication.Message;
import communication.bluethooth.Connection;

public class GameConnection {
	public static int CODE_SEND_PLAYER = 0;
	public static int CODE_SEND_SHOT = 1;
	private GameScreen game;
	public static BluetoothSocket socket;
	private Connection connection;
	public GameConnection(GameScreen _game) {
		try {
			connection = new Connection(socket);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public void sendPlayer(Player player) {
		Message message = Message.createMessage();
		message.cod = CODE_SEND_PLAYER;
		message.data = player;
		try {
			connection.write(message);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Player readPlayer() {
		try {
			Message message = connection.read(CODE_SEND_PLAYER);
			Player enemyPlayer = (Player) message.data;
			return enemyPlayer;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public void sendShot(Shot shot) {
		Message message = Message.createMessage();
		message.cod = CODE_SEND_SHOT;
		message.data = shot;
		try {
			connection.write(message);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Shot readShot() {
		try {
			Message message = connection.read(CODE_SEND_SHOT, 1000);
			return (Shot) message.data;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
